const app = getApp();
var api = require('../../../../api.js');
var mta = require('../../../../mta_analysis.js');

Page({
  data: {
    normal: 1,
    list:{
      all: 0,
      surplus: 0,
      success: 0,
      name: '',
      from: '',
      time: '',
      img: ''
    }
  },
  onLoad: function (options) {
    mta.Page.init();
  },
  onReady: function () {
  
  },
  onShow: function () {
    this.getCard();
  },
  onHide: function () {
  
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
  
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
    wx.hideShareMenu();
  },
  // 获取奖励会员卡
  getCard: function () {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    wx.request({
      url:api.card.card,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
      },
      success: function (e) {
        console.log(e);
        // var list = e.data.data[0];
        // console.log(list);
        if (e.data.code == 0) {
          that.setData({
            list: e.data.data[0],
            normal: e.data.code,
          })
        }
        //  else if (e.data.code == 1) {
        //   that.setData({
        //     normal: 1,
        //   })
        // }
      }
    });
  },
  //转赠好友
  toTransfer: function (e) {
    // console.log(e);
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/user/card/transfer/transfer?id=' + id 
    })
  },
  //领取记录
  toRecord: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/user/card/record/record?id=' + id
    })
  },

  // 转赠记录
  toTransferRecord:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/user/card/transferRecord/transferRecord?id=' + id 
    })
  }
  
})